﻿using MesErreurs;
using Metier;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Gestion_commerciale
{
    public partial class FInser_Art : Form
    {
        public FInser_Art()
        {
            InitializeComponent();
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
        }

        private void CNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void bInserer_Click(object sender, EventArgs e)
        {
            double number;
            if (CPrix.Text == "" || !Double.TryParse(CPrix.Text, out number))
            {
                MessageBox.Show("Entrez un prix au bon format");
            }
            else
            {
                number = Math.Round(number, 2);
                CPrix.Text = number.ToString();
                Article article = new Article();
                try
                {
                    article.insererArticle(CNumArticle.Text, CLibArt.Text, CQteDispo.Text, CVille.Text, CPrix.Text);
                }
                catch (MonException exception)
                {
                    MessageBox.Show(exception.MessageApplication(), exception.Message);
                }
                Close();
            }
            
        }
    }
}
